package com.baizhiedu.rsm.controller;

import com.baizhiedu.rsm.entity.ClassMessage;
import com.baizhiedu.rsm.entity.Schedule;
import com.baizhiedu.rsm.service.ClassMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * @author lby
 */
@RequestMapping("class")
@Controller
public class ClassMessageController {
    @Autowired
    private ClassMessageService classMessageService;

    /**
     * 添加班级信息
     * @return
     */
    @RequestMapping("addNewClass")
    public String addNewClass(String className){
        ClassMessage classMessage = new ClassMessage();
        classMessage.setClassname(className);
        classMessage.setClassopendate(new Date());
        classMessageService.addNewClass(classMessage);
        return "redirect:/selectclass.html";
    }

    /**
     * 获取所有班级信息
     * @return
     */
    @RequestMapping("showall")
    @ResponseBody
    public List<ClassMessage> showAll(){
        return classMessageService.showAll();
    }

    /**
     * 选中班级 跳转至学生信息显示页面
     * @param classid
     * @return
     */
    @RequestMapping("selectClassToShowStudent")
    public String selectClassToShowStudent(Integer classid, HttpSession session){
        if(classid == null){
            return "redirect:/selectclass.html";
        }
//        将班级id存入Session
        session.setAttribute("classid",classid);
        return "redirect:/showallstudent.html";
    }
}
